package com.ww.seckill.controller;


import com.ww.seckill.entity.User;
import com.ww.seckill.rabbitmq.MqSender;
import com.ww.seckill.vo.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hexiangdong
 * @since 2022-03-07
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    MqSender mqSender;

    @RequestMapping("/info")
    @ResponseBody
    public RespBean info(User user) {
        return RespBean.success(user);
    }


    /**
     * 测试发送消息
     */
    @RequestMapping("/mq")
    @ResponseBody
    public void mq() {
        mqSender.send("hello");
    }


    /**
     * 广播模式测试
     */
    @RequestMapping("/mq/fanout")
    @ResponseBody
    public void mqFanout() {
        mqSender.sendFanoutMsg("fanout");
    }

    /**
     * Direct模式测试
     */
    @RequestMapping("/mq/direct01")
    @ResponseBody
    public void mq02() {
        mqSender.sendDirectMsg01("direct msg: Hello Red");
    }

    /**
     * Direct模式测试
     */
    @RequestMapping("/mq/direct02")
    @ResponseBody
    public void mq03() {
        mqSender.sendDirectMsg02("direct msg: Hello Green");
    }

    /**
     * topic模式
     */
    @RequestMapping("/mq/topic01")
    @ResponseBody
    public void mq04() {
        mqSender.sendTopicMsg01("topic msg:mq04");
    }

    @RequestMapping("/mq/topic02")
    @ResponseBody
    public void mq05() {
        mqSender.sendTopicMsg02("topic msg:mq05");
    }

    @RequestMapping("/mq/header01")
    @ResponseBody
    public void mq06() {
        mqSender.sendHeaderMsg01("header msg:mq06");
    }

    @RequestMapping("/mq/header02")
    @ResponseBody
    public void mq07() {
        mqSender.sendHeaderMsg02("header msg:mq07");
    }
}
